.model small
					
.data
	bufDydis      DB  255
	nuskaite      DB  ?
	buferis	  DB  256 dup ('$')
	ivesk	        DB  'Iveskite eilute:', 13, 10, '$'
	rezult	  DB  'didziausias skaicius: '
	rezult2	  DB  ' '
	enteris2	  DB  13, 10, '$'	
	rezultvienas  DB  'yra tik vienas skaicius: '
	rezultvienas2 DB ' '
	enteris3	  DB  13, 10, '$'
	rezultm	  DB  'maziausias skaicius: '
	rezultm2	  DB  ' '
	enteris	  DB  13, 10, '$'
	minus1	  DB  '-1',13,10,'$'

.code

Pradzia:
	MOV	ax, @data
	MOV	ds, ax

;****nuskaito eilute****
	MOV	ah, 9			
	MOV	dx, offset ivesk
	INT	21h

	MOV	ah, 0Ah				
	MOV	dx, offset bufDydis
	INT	21h

	MOV	ah, 9
	MOV	dx, offset enteris
	INT	21h

;****algoritmas****
	SUB	ch, ch
	SUB	ax, ax
	MOV	cl, nuskaite
	MOV	bx, offset buferis
	MOV	dl, '0'
	MOV	dh, '9'
	MOV   ah, 2Fh
	MOV   al, 39h

ciklas1:
	CMP	dl, [bx]
	JA	nelygu
	CMP	dh, [bx]
	JB	nelygu
	CMP   ah, [bx]
	JA    nelygu
	MOV   ah, [bx]
	

nelygu:
	INC	bx		
	DEC	cx			
	CMP	cx, 0
	JA	ciklas1

MOV	bx, offset buferis
MOV	cl, nuskaite
SUB	ch, ch

ciklas2:
	CMP	dl, [bx]
	JA	nelygu2
	CMP	dh, [bx]
	JB	nelygu2
	CMP   al, [bx]
	JB    nelygu2
	MOV   al, [bx]

nelygu2:
	INC	bx		
	DEC	cx			
	CMP	cx, 0
	JA	ciklas2


      ;loop ciklas1
	
;****Spausdinimas****
	CMP   ah, 2Fh
	JE    minus
	
	
	CMP ah, al
	JE vienas

	MOV   [rezult2], ah
	MOV   [rezultm2], al

	MOV	ah, 9
	MOV	dx, offset rezult
	INT	21h

	CMP   al, 2Fh
	JE    minus
	MOV	ah, 9
	MOV	dx, offset rezultm
	INT	21h
	JMP   pabaiga

vienas:
	MOV   [rezultvienas2], ah
	CMP   al, 2Fh
	JE    minus
	MOV	ah, 9
	MOV	dx, offset rezultvienas
	INT	21h

	JMP   pabaiga
minus:
	MOV	ah, 9
	MOV	dx, offset minus1
	INT	21h
pabaiga:
	MOV	ah, 4Ch
	MOV	al, 0
	INT	21h

END		